package com.jeecg.demo.api;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeecg.demo.entity.VAppInformationEntity;
import com.jeecg.demo.util.URLParser;

@Api(value = "AppAdInfo", description = "信息表", tags = "AppAdInfo")
@Controller
@RequestMapping("/search_infomation")
public class NewsSearch {
	@Autowired
	private SystemService systemService;
	/**
	 * 信息搜索
	 * @param title
	 * @param pageSize
	 * @param curPage
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/searchnews", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "信息搜索", produces = "application/json")
	public ResponseMessage<List<Map<String, Object>>> list(
			@RequestParam(required = false) String title, // 关键字
			@RequestParam(required = false, defaultValue = "10") int pageSize, // 每页行数
			@RequestParam(required = false, defaultValue = "1") int curPage, // 当前页码
			HttpServletRequest request) throws Exception {
		if (StringUtil.isEmpty(title)) {
			return null;
		}
		if (title != null && !title.equals("")) {
            title = "%"+title+"%";
        }
		String sql = "SELECT * FROM V_APP_INFORMATION T WHERE STATUS = 1 AND " +
				"t.CONTENT like '"+title+"' OR TITLE like '"+title+"' ORDER BY CREATE_DATE DESC";
		List<Map<String, Object>> listMap = systemService.findForJdbcParam(sql,curPage, pageSize);
		return Result.success(listMap);
	}
	/**
	 * 热搜
	 * @return
	 */
	@RequestMapping(value = "/resou", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "热搜", produces = "application/json")
	public ResponseMessage<List<Map<String, Object>>> resoulist() {
		String sql = "select * from (select * from v_app_information  where  STATUS=1  order by create_date desc) where rownum < 11";
		List<Map<String, Object>> listMap = systemService.findForJdbc(sql);
		return Result.success(listMap);
	}
}
